﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using System.Data.Entity;

namespace HdipCricketClub.Models
{
    public class OpponentOtherFixtureDetailRepository
    {
        CricketClubEntities db = new CricketClubEntities();

        public OpponentOtherFixtureDetail GetOpponentOtherFixtureDetails(int id)
        {
            return db.OpponentOtherFixtureDetails.SingleOrDefault(cofd => cofd.fixture_id == id);
        }

        public double OpponentTotalExtras(int id)
        {
            OpponentOtherFixtureDetail opponentOtherFixtureDetail = GetOpponentOtherFixtureDetails(id);

            double opponentTotalExtras = 0;

            if (opponentOtherFixtureDetail.byes != null)
            {
                opponentTotalExtras += (double)opponentOtherFixtureDetail.byes;
            }
            if (opponentOtherFixtureDetail.leg_byes != null)
            {
                opponentTotalExtras += (double)opponentOtherFixtureDetail.leg_byes;
            }
            if (opponentOtherFixtureDetail.wides != null)
            {
                opponentTotalExtras += (double)opponentOtherFixtureDetail.wides;
            }
            if (opponentOtherFixtureDetail.no_balls != null)
            {
                opponentTotalExtras += (double)opponentOtherFixtureDetail.no_balls;
            }
            return opponentTotalExtras;
        }
    }
}